// src/components/DashboardChart.vue

<template>
  <div class="pie-chart-container">
    <div ref="pieChart" style="width: 100%; height: 400px;"></div>
  </div>
</template>

<script>
import * as echarts from 'echarts';

export default {
  name: "SalesPieChart",
  data() {
    return {
      chartInstance: null,
      option: {
        title: {
          text: '销售额分布',
          left: 'center'
        },
        tooltip: {
          trigger: 'item',
          formatter: '{a} <br/>{b}: {c} ({d}%)'
        },
        legend: {
          orient: 'vertical',
          left: 'left'
        },
        series: [
          {
            name: '销售额',
            type: 'pie',
            radius: '55%',
            data: [
              { value: 650, name: '日销售额' },
              { value: 17000, name: '月销售额' },
              { value: 250000, name: '年销售额' }
            ],
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: 'rgba(0, 0, 0, 0.5)'
              }
            }
          }
        ]
      }
    };
  },
  mounted() {
    this.chartInstance = echarts.init(this.$refs.pieChart);
    this.chartInstance.setOption(this.option);
  },
  beforeDestroy() {
    if (this.chartInstance) {
      this.chartInstance.dispose();
    }
  }
};
</script>

<style scoped>
.pie-chart-container {
  width: 100%;
  height: 400px; 
}
</style>

